var app = getApp();
Page({

  data: {
	  cdnUrl: '',
    userInfo: null,
		/* 自定义导航栏参数 */
		loading: false,
		color: '#FFFFFF',
		background: '#FFFFFF',
		show: true,
		animated: false,
		back: true,
		title: "用户昵称"
  },

  onLoad: function (options) {
		var that = this;
    that.setData({
      cdnUrl: app.cdnUrl,
      userInfo: app.globalData.userInfo
    });
  },

  onShow: function () {
		var that = this;
		that.setData({
			cdnUrl: app.cdnUrl,
		});
    if (!app.globalData.userInfo) {
      app.error("请登录后再操作", function () {
        setTimeout(function () { wx.navigateBack({}) }, 2000);
      });
    }
  },

  formSubmit: function (event) {
    var that = this;
    if (event.detail.value.username == '') {
      app.error('用户名不能为空');
      return;
    }
    app.request('/addons/cms/wxapp.user/profile', event.detail.value, function (data) {
      that.setData({ userInfo: data.userInfo });
      app.globalData.userInfo = data.userInfo;
      app.success('修改成功!', function () {
        setTimeout(function () {
          //要延时执行的代码
          wx.navigateBack({})
        }, 2000); //延迟时间
      });
    }, function (data, ret) {
      app.error(ret.msg);
    });
  }

})